package com.hsjk.szwj.module.train.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.net.URLEncodeUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hsjk.szwj.framework.common.constant.CommonConstant;
import com.hsjk.szwj.framework.common.constant.RedisKeyConstant;
import com.hsjk.szwj.framework.common.exception.ServiceException;
import com.hsjk.szwj.framework.common.exception.enums.GlobalErrorCodeConstants;
import com.hsjk.szwj.framework.common.pojo.PageResult;
import com.hsjk.szwj.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.hsjk.szwj.framework.security.core.util.SecurityFrameworkUtils;
import com.hsjk.szwj.framework.tenant.core.aop.TenantIgnore;
import com.hsjk.szwj.framework.tenant.core.context.TenantContextHolder;
import com.hsjk.szwj.module.member.api.user.MemberUserApi;
import com.hsjk.szwj.module.member.api.user.dto.MemberUserRespDTO;
import com.hsjk.szwj.module.pay.api.IMchDivisionReceiverApi;
import com.hsjk.szwj.module.pay.api.dto.MchDivisionReceiverDTO;
import com.hsjk.szwj.module.system.api.tenant.TenantApi;
import com.hsjk.szwj.module.system.api.tenant.dto.TenantRespDTO;
import com.hsjk.szwj.module.train.controller.admin.vo.*;
import com.hsjk.szwj.module.train.controller.app.vo.baijiayun.PlayerTokenRespVO;
import com.hsjk.szwj.module.train.controller.app.vo.course.*;
import com.hsjk.szwj.module.train.convert.AppCourseConvert;
import com.hsjk.szwj.module.train.convert.CourseConvert;
import com.hsjk.szwj.module.train.convert.ProductConvert;
import com.hsjk.szwj.module.train.dal.dataobject.config.CourseMockExamConfigDO;
import com.hsjk.szwj.module.train.dal.dataobject.course.*;
import com.hsjk.szwj.module.train.dal.dataobject.employee.EmployeeDO;
import com.hsjk.szwj.module.train.dal.dataobject.product.ProductSkuBindDO;
import com.hsjk.szwj.module.train.dal.dataobject.product.ProductSkuDO;
import com.hsjk.szwj.module.train.dal.dataobject.product.ProductSpuDO;
import com.hsjk.szwj.module.train.dal.dataobject.question.QuestionSetDO;
import com.hsjk.szwj.module.train.dal.dataobject.question.QuestionSetMappingDO;
import com.hsjk.szwj.module.train.dal.mysql.config.ICourseMockExamConfigMapper;
import com.hsjk.szwj.module.train.dal.mysql.course.*;
import com.hsjk.szwj.module.train.dal.mysql.employee.IEmployeeMapper;
import com.hsjk.szwj.module.train.dal.mysql.product.IProductSkuBindMapper;
import com.hsjk.szwj.module.train.dal.mysql.product.IProductSkuMapper;
import com.hsjk.szwj.module.train.dal.mysql.product.IProductSpuMapper;
import com.hsjk.szwj.module.train.dal.mysql.question.IQuestionSetMapper;
import com.hsjk.szwj.module.train.dal.mysql.question.IQuestionSetMappingMapper;
import com.hsjk.szwj.module.train.enums.CourseItemTypeEnum;
import com.hsjk.szwj.module.train.enums.ProductSkuBindTypeEnum;
import com.hsjk.szwj.module.train.service.ICourseItemService;
import com.hsjk.szwj.module.train.service.ICourseService;
import com.hsjk.szwj.module.train.service.IEmployeeService;
import com.hsjk.szwj.module.train.service.ISkuDivisionService;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.DigestUtils;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.hsjk.szwj.framework.web.core.util.WebFrameworkUtils.getLoginUserId;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/08/04 01:13
 **/
@Service
@Slf4j
public class EmployeeServiceImpl implements IEmployeeService {

    @Resource
    private IEmployeeMapper employeeMapper;

    @Override
    public List<EmployeeDO> getList(String type) {
        return employeeMapper.getList(type);
    }

    @Override
    public PageResult<EmployeeDO> getEmployeePage(AdminEmployeePageReqVO reqVO) {
        Page<AdminEmployeePageReqVO> page = new Page<>(reqVO.getPageNo(), reqVO.getPageSize());
        IPage<EmployeeDO> adminPage = employeeMapper.selectAdminPage(page, reqVO);
        return new PageResult<>(adminPage.getRecords(), adminPage.getTotal());
    }

    @Override
    public Boolean createModuleEmployee(EmployeeDO reqVO) {
        int insert = employeeMapper.insert(reqVO);
        return insert > 0 ? Boolean.TRUE : Boolean.FALSE;
    }

    @Override
    public EmployeeDO getAdminEmployeeDetail(Long id) {
        return employeeMapper.selectById(id);
    }

    @Override
    public Boolean updateModuleEmployee(EmployeeDO reqVO) {
        int insert = employeeMapper.updateById(reqVO);
        return insert > 0 ? Boolean.TRUE : Boolean.FALSE;
    }

    @Override
    public Boolean deleteModuleEmployee(Long id) {
        int result = employeeMapper.deleteById(id);
        return result > 0 ? Boolean.TRUE : Boolean.FALSE;
    }
}
